package com.beemans.corekit.integration.admob;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.LifecycleOwner;

import com.google.android.gms.ads.MobileAds;

public final class AbAdvertManager {

    public static void init(@NonNull Context context) {
        MobileAds.initialize(context);
    }


    // =================================== 信息流广告 ===================================

    /**
     * @param advertConfig 广告配置
     * @return 信息流广告是否已准备完毕
     */
    public static boolean isNativeAdvertReady(
            @NonNull AbNativeAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isNativeAdvertReady(placementId);
    }

    /**
     * @param advertConfig 广告配置
     * @return 信息流广告是否正在加载
     */
    public static boolean isNativeAdvertLoading(
            @NonNull AbNativeAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isNativeAdvertLoading(placementId);
    }

    /**
     * 加载信息流广告
     *
     * @param lifecycleOwner   传入 FragmentActivity 或 Fragment
     * @param advertConfig     广告配置
     * @param nativeSelfRender 自渲染视图
     * @param advertCallback   广告回调
     */
    public static void loadNativeAdvert(
            @NonNull LifecycleOwner lifecycleOwner,
            @NonNull AbNativeAdvertConfig advertConfig,
            @Nullable IAbNativeSelfRender nativeSelfRender,
            @Nullable AbNativeAdvertCallback advertCallback
    ) {
        final AbNativeAdvert nativeAdvert = new AbNativeAdvert(
                lifecycleOwner,
                advertConfig,
                nativeSelfRender,
                advertCallback
        );
        nativeAdvert.loadAdvert();
    }

    // =================================== 信息流广告 ===================================


    // =================================== 横幅广告 ===================================

    /**
     * 加载横幅广告
     *
     * @param lifecycleOwner  传入 FragmentActivity 或 Fragment
     * @param advertContainer 广告容器
     * @param advertConfig    广告配置
     * @param advertCallback  广告回调
     */
    public static void loadBannerAdvert(
            @NonNull LifecycleOwner lifecycleOwner,
            @NonNull ViewGroup advertContainer,
            @NonNull AbBannerAdvertConfig advertConfig,
            @Nullable AbBannerAdvertCallback advertCallback
    ) {
        final AbBannerAdvert bannerAdvert = new AbBannerAdvert(
                lifecycleOwner,
                advertContainer,
                advertConfig,
                advertCallback
        );
        bannerAdvert.loadAdvert();
    }

    // =================================== 横幅广告 ===================================


    // =================================== 开屏广告 ===================================

    /**
     * @param advertConfig 广告配置
     * @return 开屏广告是否已准备完毕
     */
    public static boolean isSplashAdvertReady(
            @NonNull AbSplashAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isSplashAdvertReady(placementId);
    }

    /**
     * @param advertConfig 广告配置
     * @return 开屏广告是否正在加载
     */
    public static boolean isSplashAdvertLoading(
            @NonNull AbSplashAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isSplashAdvertLoading(placementId);
    }

    /**
     * 加载开屏广告
     *
     * @param lifecycleOwner 传入 FragmentActivity 或 Fragment
     * @param advertConfig   广告配置
     * @param advertCallback 广告回调
     */
    public static void loadSplashAdvert(
            @NonNull LifecycleOwner lifecycleOwner,
            @NonNull AbSplashAdvertConfig advertConfig,
            @Nullable AbSplashAdvertCallback advertCallback
    ) {
        final AbSplashAdvert splashAdvert = new AbSplashAdvert(
                lifecycleOwner,
                advertConfig,
                advertCallback
        );
        splashAdvert.loadAdvert();
    }

    // =================================== 开屏广告 ===================================


    // =================================== 插屏广告 ===================================

    /**
     * @param advertConfig 广告配置
     * @return 插屏广告是否已准备完毕
     */
    public static boolean isInertAdvertReady(
            @NonNull AbInsertAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isInsertAdvertReady(placementId);
    }

    /**
     * @param advertConfig 广告配置
     * @return 插屏广告是否正在加载
     */
    public static boolean isInertAdvertLoading(
            @NonNull AbInsertAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isInsertAdvertLoading(placementId);
    }

    /**
     * 加载插屏广告
     *
     * @param lifecycleOwner 传入 FragmentActivity 或 Fragment
     * @param advertConfig   广告配置
     * @param advertCallback 广告回调
     */
    public static void loadInsertAdvert(
            @NonNull LifecycleOwner lifecycleOwner,
            @NonNull AbInsertAdvertConfig advertConfig,
            @Nullable AbInsertAdvertCallback advertCallback
    ) {
        final AbInsertAdvert insertAdvert = new AbInsertAdvert(
                lifecycleOwner,
                advertConfig,
                advertCallback
        );
        insertAdvert.loadAdvert();
    }

    // =================================== 插屏广告 ===================================


    // =================================== 激励广告 ===================================

    /**
     * @param advertConfig 广告配置
     * @return 激励广告是否已准备完毕
     */
    public static boolean isRewardAdvertReady(
            @NonNull AbRewardAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isRewardAdvertReady(placementId);
    }

    /**
     * @param advertConfig 广告配置
     * @return 激励广告是否正在加载
     */
    public static boolean isRewardAdvertLoading(
            @NonNull AbRewardAdvertConfig advertConfig
    ) {
        final String placementId = advertConfig.getPlacementId();
        return AbAdvertLoadManager.getInstance().isRewardAdvertLoading(placementId);
    }

    /**
     * 加载激励广告
     *
     * @param lifecycleOwner 传入 FragmentActivity 或 Fragment
     * @param advertConfig   广告配置
     * @param advertCallback 广告回调
     */
    public static void loadRewardAdvert(
            @NonNull LifecycleOwner lifecycleOwner,
            @NonNull AbRewardAdvertConfig advertConfig,
            @Nullable AbRewardAdvertCallback advertCallback
    ) {
        final AbRewardAdvert rewardAdvert = new AbRewardAdvert(
                lifecycleOwner,
                advertConfig,
                advertCallback
        );
        rewardAdvert.loadAdvert();
    }

    // =================================== 激励广告 ===================================
}